<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>地址管理</title>
		<link rel="stylesheet" href="//at.alicdn.com/t/font_604979_y7b682z2miey7gb9.css" />
		<link rel="stylesheet" type="text/css" href="$!rc.contextPath/common/common.css"/>
		<link rel="stylesheet" type="text/css" href="$!rc.contextPath/css/addressmanage1.css"/>
	</head>
	<body>
		<!--头-->
		<div class="title text-center">
			<a onClick="javascript:window.history.go(-1)"><</a>
			地址管理
		</div>
		<!--主体-->
		<article style="margin-top:4.5rem;">
			<form class="manageAddress">
				<ul>
					#foreach($addr in $list)
					<li id="addr_$!addr.delivery_addr_id">
						<img src="$!rc.contextPath/img/icon/li_border.png">
						<div>
							<div class="person_info" onclick="f_choose('$!addr.delivery_addr_id')">
								<span>$!addr.delivery_receiver</span>
								<span>$!addr.delivery_mobile</span>
							</div>
							<div class="address_info" onclick="f_choose('$!addr.delivery_addr_id')">
								<i class="iconfont icon-dingwei1"></i>
								<span>$!addr.delivery_address</span>
							</div>
							<div class="edit_info">
								<label  #if ($!addr.is_default == 'N') onclick="f_set('$!addr.delivery_addr_id');" #end class="read-box clearfix" id="s1">
									
									<input type="radio" #if ($!addr.is_default == 'Y') checked="checked" #end name="default-add" id="s1"/>
									<span>设为默认</span>
								</label>
								<div class="operate_info">
									<span><i class="iconfont icon-edit" onclick="f_edit('$!addr.delivery_addr_id')">编辑</i></span>
									<span class="delete" val="$!addr.delivery_addr_id" st="$!addr.is_default"><i class="iconfont icon-xiazai14">删除</i></span>
								</div>
							</div>
						</div>
						<img src="$!rc.contextPath/img/icon/li_border.png">
					</li>
					#end
					<a href="$!rc.contextPath/memberView/addAddr" class="btn_add">新增地址</a>
				</ul>
			</form>
		</article>
		<script src="$!rc.contextPath/common/jquery-1.8.3.min.js"></script>
		<!--删除地址-->
		<div class="address_win">
		    <div class="address_win_box">
		        <div class="address_win_tit">你确定删除该地址吗？</div>
		        <div class="address_btn clearfix">
		            <a href="#" class="cancle f_left">取消</a>
		            <a href="javascript:f_del()" class="submit f_right">确定</a>
		        </div>
		
		    </div>
		</div>
		<script type="text/javascript">
			
			var that;
			var id;
		    $('.delete').on('click',function(){
		    		if($(this).attr("st") == 'Y'){
		    			$(".address_win_tit").html("请先选择其他地址设为默认！")
		    			id = 0;
		    		}else{
		    			id = $(this).attr("val");
		    		}
		            $('.address_win').show();
		            that = $(this);
		            
		    });
		
		    $('.cancle').on('click',function(){
		        $('.address_win').hide();
		    })
		    /* $('.submit').on('click',function(){
		        that.parent().parent().parent().parent().remove();
		        $('.address_win').hide();
		    }) */
		    
		    function f_set(addrId){
		    	$.ajax({
		            type: 'POST',
		            url: '$!rc.contextPath/member/setAddr',
		            data : {
		            	addrId : addrId
		            },
		            dataType: 'json',
		            success: function(data){
		                console.log(data);
		                if(data.code != '0'){
		                	alert(data.text)
		                }else{
		                	/* window.location.reload(); */
		                }
		            }
		        });
		    }
		    
		    function f_del(){
		    	if(id > 0){
		    		$.ajax({
			            type: 'POST',
			            url: '$!rc.contextPath/member/delAddr',
			            data : {
			            	addrId : id
			            },
			            dataType: 'json',
			            success: function(data){
			                console.log(data);
			                if(data.code != '0'){
			                	alert(data.text)
			                }else{
			                	$("#addr_" + id).remove();
			                	$('.address_win').hide();
			                }
			            }
			        });
		    	}else{
		    		$('.address_win').hide();
		    	}
		    }
		    
		    function f_edit(addrId){
		    	window.location.href = '$!rc.contextPath/memberView/updateAddr?addrId=' + addrId;
		    }
		    
		    function f_choose(addrId){
		    	if(document.referrer.indexOf("pay?skuId") != -1)
		    		window.location.href = document.referrer + "&addrId=" + addrId;
		    	else
		    		window.history.go(-3);
		    }
		</script>
	</body>
</html>
